package org.springcloud.wisdom.spring_01_canteen.address;

import org.apache.ibatis.annotations.*;
import org.springcloud.wisdom.spring_01_canteen.dishes.fordishes.Dishes;

import java.util.List;

@Mapper
public interface AddressDao {
    //根据stuid查自己的地址
    @Select("<script>" +
            "SELECT * FROM wisdom.address" +
            "<where>" +
            "   <if test=\"stuid != null\">" +
            "      and stuid = #{stuid}" +
            "   </if>" +
            "   <if test=\"status != null\">" +
            "      and status = #{status}" +
            "   </if>" +
            "</where>" +
            "</script>")
    List<Address> canaddress(Integer stuid,String status);

    //更新地址
    @Update("<script>" +
            "  update address" +
            "        <set>" +
            "            <if test=\"null != name\"> " +
            "                name = #{name}," +
            "            </if>" +
            "            <if test=\"null != address\"> " +
            "                address = #{address}," +
            "            </if>" +
            "            <if test=\"null!= phone\"> " +
            "                phone = #{phone}," +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    public int update(Address address);

    //删除地址
    @Delete("DELETE FROM wisdom.address where id=#{id}")
    public int del(Integer did);

    //添加地址
    @Insert("INSERT INTO wisdom.address (stuid,name,address,phone) values" +
            "(#{stuid},#{name},#{address},#{phone})")
    public int add(Address address);
    /*设置默认地址*/
    // 将所有地址的status设置为0
    @Update("UPDATE wisdom.address SET status = '0'")
    int resetAllStatusesToNonDefault();

    // 将特定ID地址的status设置为1
    @Update("UPDATE wisdom.address SET status = '1' WHERE id = #{id}")
    int setDefaultAddressStatus(@Param("id") Integer id);
}
